package clustering_algorithms;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;

/****
 * 
 * improved version of the k-means++
 *
 */
public class k_means_improved extends k_means_plus {

	public k_means_improved(
			ArrayList<HashMap<Integer, Float>> vectors_to_cluster,
			int number_of_clusters, 
			float maximal_centroid_movement, 
			HashMap<Integer, Integer> termid_to_frquenecy)
			throws IOException {
		super(vectors_to_cluster, number_of_clusters, maximal_centroid_movement);		
		//choos only terms that exist in 30% of single cluster size
		Float minimal_frequency = ((float)vectors_to_cluster.size() /(float)number_of_clusters)*0.3f; 
		
		for(int i =0; i< vectors_to_cluster.size();++i)
		{
			Iterator<Entry<Integer, Float>> term_it = vectors_to_cluster.get(i).entrySet().iterator();
			while(term_it.hasNext())
			{
				Entry<Integer, Float> entry = term_it.next(); 
				Float val = entry.getValue();				
				if(termid_to_frquenecy.get(entry.getKey()) < minimal_frequency)
				{
					term_it.remove();
				}
			}
		}
	}
}
		
		 
		
	


